package com.ztjava.portal.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.ehcache.CacheKit;
import com.ztjava.core.Constant;
import com.ztjava.core.HModel;

public class PortalUser extends Model<PortalUser> implements HModel{
	public static PortalUser dao = new PortalUser();
	public static String tablename = "h_portal_user";
	
	private String[][] columns = new String[][]{
			new String[]{"username","varchar","50"},
			new String[]{"password","varchar","100"},
			new String[]{"fullname","varchar","80"},
			new String[]{"email","varchar","60"},
			new String[]{"phone","varchar","80"},
			new String[]{"enable_flag","varchar","1","T"},
			new String[]{"update_user","int","11"},
			new String[]{"create_user","int","11"}
	};
	@Override
	public String[][] getColumns() {
		return columns;
	}
	@Override
	public String getTablename() {
		return tablename;
	}
	
	public static void loadUserFullnameCache(){
		List<Record> list = Db.find("select CONCAT(id,'') as value,fullname as name from "+PortalUser.tablename+" order by id asc");
		Map<String,Record> map = new HashMap<String,Record>();
		for(int i=0;i<list.size();i++){
			map.put(list.get(i).getStr("value"), list.get(i));
		}
		CacheKit.put(Constant.CacheData,"BACK_USER_CACHE", map);
	}
}
